﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using Hangjing.DBUtility;
using Hangjing.Model;

namespace Hangjing.SQLServerDAL
{
    /// <summary>
    /// 骑士个人信息
    /// </summary>
    public partial class deliverInformation
    {

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(deliverInformationInfo model)
        {
            SqlParameter[] parameters = 
			{
			    new SqlParameter("@deliverid", SqlDbType.Int,4) ,            
                new SqlParameter("@address", SqlDbType.VarChar,256) ,            
                new SqlParameter("@Marriage", SqlDbType.VarChar,50) ,            
                new SqlParameter("@homeaddress", SqlDbType.VarChar,256) ,            
                new SqlParameter("@Nation", SqlDbType.VarChar,50) ,            
                new SqlParameter("@QQ", SqlDbType.VarChar,20) ,            
                new SqlParameter("@Education", SqlDbType.VarChar,50) ,            
                new SqlParameter("@Emergency", SqlDbType.VarChar,50) ,            
                new SqlParameter("@Emergencyphone", SqlDbType.VarChar,50) ,            
                new SqlParameter("@Entrytime", SqlDbType.VarChar,50) ,            
                new SqlParameter("@Salarycard", SqlDbType.VarChar,50) ,            
                new SqlParameter("@Bank", SqlDbType.VarChar,50) ,            
                new SqlParameter("@workexperience", SqlDbType.Text) ,            
                new SqlParameter("@Reward", SqlDbType.Text) ,            
                new SqlParameter("@Complaint", SqlDbType.Text) ,            
                new SqlParameter("@Bond", SqlDbType.Float,8) ,            
                new SqlParameter("@age", SqlDbType.Int,4) ,            
                new SqlParameter("@remark", SqlDbType.Text) ,            
                new SqlParameter("@reveint1", SqlDbType.Int,4) ,            
                new SqlParameter("@reveint2", SqlDbType.Int,4) ,            
                new SqlParameter("@reveint3", SqlDbType.VarChar,4000) ,            
                new SqlParameter("@revevar1", SqlDbType.VarChar,256) ,            
                new SqlParameter("@revevar2", SqlDbType.Text) ,            
                new SqlParameter("@revevar3", SqlDbType.VarChar,256) ,            
                new SqlParameter("@revedate1", SqlDbType.DateTime)             
          
            };

            parameters[0].Value = model.deliverid;
            parameters[1].Value = model.address;
            parameters[2].Value = model.Marriage;
            parameters[3].Value = model.homeaddress;
            parameters[4].Value = model.Nation;
            parameters[5].Value = model.QQ;
            parameters[6].Value = model.Education;
            parameters[7].Value = model.Emergency;
            parameters[8].Value = model.Emergencyphone;
            parameters[9].Value = model.Entrytime;
            parameters[10].Value = model.Salarycard;
            parameters[11].Value = model.Bank;
            parameters[12].Value = model.workexperience;
            parameters[13].Value = model.Reward;
            parameters[14].Value = model.Complaint;
            parameters[15].Value = model.Bond;
            parameters[16].Value = model.age;
            parameters[17].Value = model.remark;
            parameters[18].Value = model.reveint1;
            parameters[19].Value = model.reveint2;
            parameters[20].Value = model.reveint3;
            parameters[21].Value = model.revevar1;
            parameters[22].Value = model.revevar2;
            parameters[23].Value = model.revevar3;
            parameters[24].Value = model.revedate1;
            return SQLHelper.ExecuteNonQuery(CommandType.StoredProcedure, "deliverInformation_ADD", parameters);
        }


        /// <summary>
        /// 获取记录所有字段
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <param>Id</param>
        /// <returns>deliverInformationInfo</returns>
        public deliverInformationInfo GetModel(int Id)
        {
            string sql = "select Id,deliverid,address,Marriage,homeaddress,Nation,QQ,Education,Emergency,Emergencyphone,Entrytime,Salarycard,Bank,workexperience,Reward,Complaint,Bond,age,reveint1,reveint2,reveint3,revevar1,revevar2,revevar3,revedate1,remark from deliverInformation where  Id = @Id";
            SqlParameter parameter = new SqlParameter("@Id", SqlDbType.Int, 4);
            parameter.Value = Id;
            deliverInformationInfo model = null;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.Text, sql, parameter))
            {
                if (dr.Read())
                {
                    model = new deliverInformationInfo();
                    model.Id = HJConvert.ToInt32(dr["Id"]);
                    model.deliverid = HJConvert.ToInt32(dr["deliverid"]);
                    model.address = HJConvert.ToString(dr["address"]);
                    model.Marriage = HJConvert.ToString(dr["Marriage"]);
                    model.homeaddress = HJConvert.ToString(dr["homeaddress"]);
                    model.Nation = HJConvert.ToString(dr["Nation"]);
                    model.QQ = HJConvert.ToString(dr["QQ"]);
                    model.Education = HJConvert.ToString(dr["Education"]);
                    model.Emergency = HJConvert.ToString(dr["Emergency"]);
                    model.Emergencyphone = HJConvert.ToString(dr["Emergencyphone"]);
                    model.Entrytime = HJConvert.ToString(dr["Entrytime"]);
                    model.Salarycard = HJConvert.ToString(dr["Salarycard"]);
                    model.Bank = HJConvert.ToString(dr["Bank"]);
                    model.workexperience = HJConvert.ToString(dr["workexperience"]);
                    model.Reward = HJConvert.ToString(dr["Reward"]);
                    model.Complaint = HJConvert.ToString(dr["Complaint"]);
                    model.Bond = HJConvert.ToDecimal(dr["Bond"]);
                    model.age = HJConvert.ToInt32(dr["age"]);
                    model.reveint1 = HJConvert.ToInt32(dr["reveint1"]);
                    model.reveint2 = HJConvert.ToInt32(dr["reveint2"]);
                    model.reveint3 = HJConvert.ToString(dr["reveint3"]);
                    model.revevar1 = HJConvert.ToString(dr["revevar1"]);
                    model.revevar2 = HJConvert.ToString(dr["revevar2"]);
                    model.revevar3 = HJConvert.ToString(dr["revevar3"]);
                    model.revedate1 = HJConvert.ToDateTime(dr["revedate1"]);
                    model.remark = HJConvert.ToString(dr["remark"]);
                }
            }
            return model;
        }

        /// <summary>
        /// 根据配送员编号获取信息
        /// </summary>
        /// <param name="deliverid"></param>
        /// <returns></returns>
        public deliverInformationInfo GetModelByDeliverID(int deliverid)
        {
            string sql = "select * from deliverInformation where  deliverid = @Id";
            SqlParameter parameter = new SqlParameter("@Id", SqlDbType.Int, 4);
            parameter.Value = deliverid;
            deliverInformationInfo model = null;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.Text, sql, parameter))
            {
                if (dr.Read())
                {
                    model = new deliverInformationInfo();
                    model.Id = HJConvert.ToInt32(dr["Id"]);
                    model.deliverid = HJConvert.ToInt32(dr["deliverid"]);
                    model.address = HJConvert.ToString(dr["address"]);
                    model.Marriage = HJConvert.ToString(dr["Marriage"]);
                    model.homeaddress = HJConvert.ToString(dr["homeaddress"]);
                    model.Nation = HJConvert.ToString(dr["Nation"]);
                    model.QQ = HJConvert.ToString(dr["QQ"]);
                    model.Education = HJConvert.ToString(dr["Education"]);
                    model.Emergency = HJConvert.ToString(dr["Emergency"]);
                    model.Emergencyphone = HJConvert.ToString(dr["Emergencyphone"]);
                    model.Entrytime = HJConvert.ToString(dr["Entrytime"]);
                    model.Salarycard = HJConvert.ToString(dr["Salarycard"]);
                    model.Bank = HJConvert.ToString(dr["Bank"]);
                    model.workexperience = HJConvert.ToString(dr["workexperience"]);
                    model.Reward = HJConvert.ToString(dr["Reward"]);
                    model.Complaint = HJConvert.ToString(dr["Complaint"]);
                    model.Bond = HJConvert.ToDecimal(dr["Bond"]);
                    model.age = HJConvert.ToInt32(dr["age"]);
                    model.reveint1 = HJConvert.ToInt32(dr["reveint1"]);
                    model.reveint2 = HJConvert.ToInt32(dr["reveint2"]);
                    model.reveint3 = HJConvert.ToString(dr["reveint3"]);
                    model.revevar1 = HJConvert.ToString(dr["revevar1"]);
                    model.revevar2 = HJConvert.ToString(dr["revevar2"]);
                    model.revevar3 = HJConvert.ToString(dr["revevar3"]);
                    model.revedate1 = HJConvert.ToDateTime(dr["revedate1"]);
                    model.remark = HJConvert.ToString(dr["remark"]);
                }
            }
            return model;
        }



        /// <summary>
        /// 获得总记录数
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int GetCount(string strWhere)
        {
            return (int)SQLHelper.ExecuteScalar(CommandType.StoredProcedure, "pagecount", new SqlParameter("@tblName", "deliverInformation"), new SqlParameter("@strWhere", strWhere));
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pagesize">页尺寸</param>
        /// <param name="pageindex">页索引</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="orderName">排序字段</param>
        /// <param name="orderType">排序类型，1为降序，0为升序</param>
        /// <returns>图书列表</returns>
        ///此代码由杭景科技代码内部生成器自动生成
        public IList<deliverInformationInfo> GetList(int pagesize, int pageindex, string strWhere, string orderName, int orderType)
        {
            IList<deliverInformationInfo> infos = new List<deliverInformationInfo>();
            SqlParameter[] parameters = 
			{
				new SqlParameter("@tblName", SqlDbType.VarChar,255),
				new SqlParameter("@strGetFields", SqlDbType.VarChar,1000),
				new SqlParameter("@primary", SqlDbType.VarChar,255),
				new SqlParameter("@orderName", SqlDbType.VarChar,255),
				new SqlParameter("@PageSize", SqlDbType.Int),
				new SqlParameter("@PageIndex", SqlDbType.Int),
				new SqlParameter("@OrderType", SqlDbType.Bit),
				new SqlParameter("@strWhere", SqlDbType.VarChar,1500)
			};
            parameters[0].Value = "deliverInformation";
            parameters[1].Value = "Id,deliverid,address,Marriage,homeaddress,Nation,QQ,Education,Emergency,Emergencyphone,Entrytime,Salarycard,Bank,workexperience,Reward,Complaint,Bond,age,reveint1,reveint2,reveint3,revevar1,revevar2,revevar3,revedate1,remark";
            parameters[2].Value = "Id";
            parameters[3].Value = orderName;
            parameters[4].Value = pagesize;
            parameters[5].Value = pageindex;
            parameters[6].Value = orderType;
            parameters[7].Value = strWhere;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.StoredProcedure, "pageselectpri", parameters))
            {
                while (dr.Read())
                {
                    deliverInformationInfo info = new deliverInformationInfo();
                    info.Id = HJConvert.ToInt32(dr["Id"]);
                    info.deliverid = HJConvert.ToInt32(dr["deliverid"]);
                    info.address = HJConvert.ToString(dr["address"]);
                    info.Marriage = HJConvert.ToString(dr["Marriage"]);
                    info.homeaddress = HJConvert.ToString(dr["homeaddress"]);
                    info.Nation = HJConvert.ToString(dr["Nation"]);
                    info.QQ = HJConvert.ToString(dr["QQ"]);
                    info.Education = HJConvert.ToString(dr["Education"]);
                    info.Emergency = HJConvert.ToString(dr["Emergency"]);
                    info.Emergencyphone = HJConvert.ToString(dr["Emergencyphone"]);
                    info.Entrytime = HJConvert.ToString(dr["Entrytime"]);
                    info.Salarycard = HJConvert.ToString(dr["Salarycard"]);
                    info.Bank = HJConvert.ToString(dr["Bank"]);
                    info.workexperience = HJConvert.ToString(dr["workexperience"]);
                    info.Reward = HJConvert.ToString(dr["Reward"]);
                    info.Complaint = HJConvert.ToString(dr["Complaint"]);
                    info.Bond = HJConvert.ToDecimal(dr["Bond"]);
                    info.age = HJConvert.ToInt32(dr["age"]);
                    info.reveint1 = HJConvert.ToInt32(dr["reveint1"]);
                    info.reveint2 = HJConvert.ToInt32(dr["reveint2"]);
                    info.reveint3 = HJConvert.ToString(dr["reveint3"]);
                    info.revevar1 = HJConvert.ToString(dr["revevar1"]);
                    info.revevar2 = HJConvert.ToString(dr["revevar2"]);
                    info.revevar3 = HJConvert.ToString(dr["revevar3"]);
                    info.revedate1 = HJConvert.ToDateTime(dr["revedate1"]);
                    info.remark = HJConvert.ToString(dr["remark"]);
                    infos.Add(info);
                }
            }
            return infos;
        }

        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="Id"></param>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <returns></returns>
        public int DeldeliverInformation(int Id)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from deliverInformation where Id=@Id");
            SqlParameter[] Para = 
			{
				new SqlParameter("@Id",SqlDbType.Int)
			};
            Para[0].Value = Id;

            return SQLHelper.ExecuteNonQuery(CommandType.Text, str.ToString(), Para);
        }


        /// <summary>
        /// 批量删除记录
        /// </summary>
        /// <param name="IdList"></param>
        /// <returns></returns>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int DelList(string IdList)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from deliverInformation where Id in ({0})");

            return SQLHelper.ExecuteNonQuery(CommandType.Text, string.Format(str.ToString(), IdList), null);
        }




    }
}

